package com.nfit.shopadmin.controller;

import com.nfit.shopadmin.service.CartService;
import com.nfit.shopadmin.service.OrderService;
import com.nfit.shopmodel.dto.order.OrderDto;
import com.nfit.shopmodel.entity.order.OrderInfo;
import com.nfit.shopmodel.vo.common.Result;
import com.nfit.shopmodel.vo.common.ResultCodeEnum;
import com.nfit.shopmodel.vo.order.OrderItemVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:OrderController
 * Package:com.nfit.shopadmin.controller
 * Description
 *
 * @Author L
 * @Create 2025/1/6 0:09
 */
@Slf4j
@Tag(name = "订单控制层")
@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    /**
     * 查询预付订单项
     */
    @GetMapping("/getOrderItemList")
    public Result getOrderItemList(){
        OrderItemVo orderItemVo = orderService.getOrderItem();
        return Result.build(orderItemVo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询立即购买订单项
     */
    @GetMapping("/getOrderItemNow/{skuId}/{count}")
    public Result getOrderItemNow(@PathVariable("skuId") Long skuId,
                                  @PathVariable("count") Integer count){
        OrderItemVo orderItemVo = orderService.getOrderItemNow(skuId,count);
        //log.info("获取到的信息：{}",orderItemVo);
        return Result.build(orderItemVo, ResultCodeEnum.SUCCESS);
    }


    /**
     * 创建订单
     */
    @PostMapping("/saveOrderInfo")
    public Result saveOrderInfo(@RequestBody OrderDto orderDto){
        String orderId =  orderService.saveOrderInfo(orderDto);
        log.info("创建订单信息：{}",orderDto);
        return Result.build(orderId,ResultCodeEnum.SUCCESS);
    }

}
